$(document).ready(function(){
    var bSign = true, eSign = $('#signBtn');
    eSign.on('click', function(){
        if(bSign){
            bSign = false;
            $.post('/user/ajaxsign.html', {}, function(res){
                var data = JSON.parse(res);
                if(data.code == 200){
                    $('#updateGx').text('「'+data.data.gx+'」');
                    eSign.text('已签到').addClass('btn-ed').removeClass('btn-default').removeAttr('id');
                    eSign.append('<span id="addGxView">+'+data.data.addgx+' 贡献度</span>');
                    var eGx = $('#addGxView'), eUserSigns = $('#userSigns'), count = 15;
                    eUserSigns.text(parseInt(eUserSigns.text()) + 1);
                    var t = setInterval(function(){
                        count --;
                        eGx.css({'top': count*3 - 42, 'opacity': count/15});
                        if(count <= 0){
                            eGx.remove();
                            clearInterval(t);
                        }
                    }, 100);
                }else if(data.code == 201){
                    eSign.text('已签到').addClass('btn-ed').removeClass('btn-default').removeAttr('id');
                }else{
                    alert('签到系统出现错误，请您稍候再试！');
                }
            });
        }
    });
});